import { observable, computed, action } from "mobx";

class AppStore {
  static index = 1;
  /**
   * @description 总的苹果
   */
  @observable
  appList = [
    // {
    //   title: `红苹果${AppStore.index}号`,
    //   weight: parseInt(Math.random() * 100) + 100,
    //   has: true,
    // },
  ];
  /**
   * @description 存在的苹果
   */
  @computed
  get hasAppLists() {
    return this.appList.filter((ele) => ele.has);
  }
  /**
   * @description 吃掉的苹果
   */
  @computed
  get noHasAppLists() {
    return this.appList.filter((ele) => !ele.has);
  }

  /**
   * @description 添加苹果
   */
  @action.bound
  addApp() {
    console.log(this);
    this.appList = this.appList.concat([
      {
        title: `红苹果${AppStore.index}号`,
        weight: parseInt(Math.random() * 100) + 100,
        has: true,
      },
    ]);
    AppStore.index += 1;
  }
  /**
   *
   * @description 吃苹果
   * @param {string} title
   */
  @action.bound
  changeStatus(title) {
    this.appList = this.appList.map((ele) => {
      if (ele.title === title) {
        ele.has = !ele.has;
      }
      return ele;
    });
  }
}

const appInstance = new AppStore();
export default appInstance;
